package v2

type BlockChain struct {
	//区块链切片
	Blocks []*Block
}

// 创建创世区块,第一个初始块
func NewBlockChain() *BlockChain {
	newBlock := NewBlock([]byte{}, "创世 First one Block")
	return &BlockChain{[]*Block{newBlock}}
}

func (b *BlockChain) AddBlock(data string) {
	last := b.Blocks[len(b.Blocks)-1]
	phash := last.Hash
	newBlock := NewBlock(phash, data)
	b.Blocks = append(b.Blocks, newBlock)
}
